<template>
  <div>
    <CommonHeadQueryComponent
      slot="headContent"
      ref="acceptHandleHeadRef"
      :needMoreQuery="true"
      @onSearch="onSearch"
      @onReset="reQuery"
      @myEvent="myEvent"
    >
      <div slot="headRight" style="float: right; margin-left: auto;margin-right: 60px;">
        <a-button class="btn_primary_color" icon="edit" type="primary" @click="superviseRecordAdd">
          案件录入
        </a-button>
      </div>
      <!-- 其他查询条件 -->
      <div slot="more">
        <a-form layout="inline" class="accept_more_operate_moreForm">
          <a-collapse v-model="collapseKey" class="accept_more_operate_moreForm_collapse">
            <a-collapse-panel :show-arrow="false" disabled key="1" style="font-weight: bold">
              <div slot="header" class="accept_more_operate_moreForm_collapse_head">
                <a-row :gutter="48" style="width: 100%; font-weight: bold">
                  <a-col @click.stop="() => {}" :md="8" :sm="24">
                    <a-form-item label="申请人：">
                      <a-input v-model="queryParam.f_applyname" placeholder="请输入申请人" allowClear />
                    </a-form-item>
                  </a-col>
                  <a-col @click.stop="() => {}" :md="8" :sm="24">
                    <a-form-item label="被申请人：">
                      <a-input v-model="queryParam.f_targetname" placeholder="请输入被申请人" allowClear />
                    </a-form-item>
                  </a-col>
                  <a-col @click.stop="() => {}" :md="8" :sm="24">
                    <a-form-item label="来源：">
                      <a-select
                        v-model="queryParam.f_source"
                        style="width: 220px; font-weight: normal"
                        placeholder="请选择来源"
                        allowClear
                      >
                        <a-select-option v-for="item in Tp_applysourceList" :key="item.value" :value="item.value">
                          {{ item.name }}
                        </a-select-option>
                      </a-select>
                    </a-form-item>
                  </a-col>
                </a-row>
              </div>
              <a-row :gutter="48" style="width: 100%" class="accept_more_operate_moreForm_collapse_body">
                <a-col @click.stop="() => {}" :md="8" :sm="24">
                  <a-form-item label="状态">
                    <a-select
                      v-model="queryParam.f_status"
                      style="width: 220px; font-weight: normal"
                      placeholder="请选择状态"
                      allowClear
                    >
                      <a-select-option v-for="item in statusList" :key="item.value" :value="item.value">
                        {{ item.name }}
                      </a-select-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <a-col @click.stop="() => {}" :md="12" :sm="24">
                  <a-form-item label="申请时间：">
                    <a-date-picker
                      v-model="queryParam.f_applystarttime"
                      :style="{ width: 'calc(50% - 12px)' }"
                      placeholder="开始日期"
                      format="YYYY-MM-DD"
                      allowClear
                      @change="subtimeListen()"
                    />
                    ~
                    <a-date-picker
                      v-model="queryParam.f_applyendtime"
                      :style="{ width: 'calc(50% - 12px)' }"
                      placeholder="结束日期"
                      format="YYYY-MM-DD"
                      allowClear
                      @change="subtimeListen()"
                    />
                  </a-form-item>
                </a-col>
              </a-row>
            </a-collapse-panel>
          </a-collapse>
        </a-form>
      </div>

      <template slot="content">
        <!-- 表格数据 -->
        <div class="accept_content_table">
          <a-table
            :scroll="scroll"
            :columns="ucolumns"
            :data-source="listData"
            :pagination="upagination"
            :loading="loading"
            rowKey="taskid"
            @change="tableChange"
            size="middle"
            :bordered="ubordered"
            :rowClassName="rowClassName"
            :components="header"
            ref="table"
            :key="tableCountKey"
            type="checkbox"
          >
            <span slot="serial" slot-scope="text, record, index">
              {{ (upagination.current - 1) * upagination.pageSize + parseInt(index) + 1 }}
            </span>

            <div slot="statusSlot" slot-scope="text, record" style="width: 100%">
              <a-tag color="red" v-if="record.status == St_apply[6000600].value">{{ '待提交' }}</a-tag>
              <a-tag color="green" v-else > {{ '已提交' }}</a-tag>
            </div>

            <div slot="applynameSlot" slot-scope="applyname, record" class="beyond_hiding" style="width: 100%">
              <a-tooltip placement="topLeft">
                <template slot="title">
                  <span>{{ applyname }}</span>
                </template>
                {{ applyname }}
              </a-tooltip>
            </div>

            <div slot="targetnameSlot" slot-scope="text, record" class="beyond_hiding" style="width: 100%">
              <a-tooltip placement="topLeft">
                <template slot="title">
                  <span>{{ record.targetname }}</span>
                </template>
                {{ record.targetname }}
              </a-tooltip>
            </div>

            <div slot="createtimeSlot" slot-scope="createtime" class="beyond_hiding" style="width: 100%">
              {{ createtime | getTimeFormat('YYYY年M月D日') }}
            </div>

            <!-- 案件来源 -->
            <div slot="sourceSlot" slot-scope="source" class="beyond_hiding" style="width: 100%">
              {{ source in Tp_applysourceMap ? Tp_applysourceMap[source] : '' }}
            </div>

            <template slot="operation" slot-scope="text, record">
              <span v-if="record.status == St_apply[6000600].value">
                <a @click="handleForm(record.applyid, '3')">编辑</a>
                <a-divider type="vertical" />
              </span>
              <a href="javascript:;" @click="handleForm(record.applyid, '4')">详情</a>
            </template>
          </a-table>
        </div>
        <ApplyViewComponent ref="applyViewComponentRef" />
      </template>
    </CommonHeadQueryComponent>
  </div>

</template>

<script>
import { SuperviseCommonMinxin } from '@/views/supervise/SuperviseCommonMinxin'
import { queryByPage } from '@/api/supervise/apl_supervise'
import { Tp_applysourceMap } from '@/enumeration/Tp_applysource.js'
import { St_apply } from '@/enumeration/St_apply.js'
const ucolumns = [
  {
    title: '序号',
    width: 80,
    key: 'index',
    align: 'center',
    fixed: 'left',
    scopedSlots: { customRender: 'serial' }
  },
  {
    title: '状态',
    width: 120,
    key: 'status',
    align: 'center',
    fixed: 'left',
    scopedSlots: { customRender: 'statusSlot' }
  },
  {
    title: '案号',
    dataIndex: 'acceptcode',
    key: 'acceptcode',
    width: 250,
    align: 'center'
  },
  {
    title: '申请人名称',
    dataIndex: 'applyname',
    key: 'applyname',
    width: 220,
    align: 'center',
    scopedSlots: { customRender: 'applynameSlot' }
  },
  {
    title: '被申请人名称',
    dataIndex: 'targetname_text',
    key: 'targetname_text',
    width: 250,
    align: 'center',
    scopedSlots: { customRender: 'targetnameSlot' }
  },
  {
    title: '申请时间',
    dataIndex: 'createtime',
    key: 'createtime',
    align: 'center',
    width: 200,
    scopedSlots: { customRender: 'createtimeSlot' }
  },
  {
    title: '案件来源',
    width: 150,
    dataIndex: 'source',
    align: 'center',
    scopedSlots: { customRender: 'sourceSlot' }
  },
  {
    title: '录入人员',
    key: 'regusername',
    dataIndex: 'regusername',
    align: 'center',
    width: 180
  },
  {
    title: '操作',
    dataIndex: 'action',
    key: 'action',
    width: 220,
    fixed: 'right',
    align: 'center',
    scopedSlots: { customRender: 'operation' }
  }
]
const statusList = [
  {
    name: '待提交',
    value: '6000600'
  },
  {
    name: '已提交',
    value: '6000601'
  }
]
export default {
  mixins: [SuperviseCommonMinxin],
  data () {
    return {
      ucolumns: ucolumns,
      St_apply: St_apply,
      statusList: statusList,
      queryParam: {
        f_acceptcode: '', // 案号
        f_applyname: '', // 申请人
        f_regusername: '', // 录入人
        f_targetname: '', // 被申请人
        f_applystarttime: null, // 开始时间
        f_applyendtime: null, // 结束时间
        f_status: undefined, // 状态
        f_source: undefined, // 来源
        pageNumber: 1,
        pageSize: 20,
        sort: 'createtime',
        order: 'desc'
      },
      Tp_applysourceMap: Tp_applysourceMap
    }
  },
  components: {
    ApplyViewComponent: () => import('@/views/accept/component/ApplyViewComponent.vue')
  },
  created () {
    try{
      if(localStorage.getItem('SuperviseDraft')){
        this.queryParam = JSON.parse(localStorage.getItem('SuperviseDraft'))
        console.log('this.queryParam.SuperviseDraft',this.queryParam);
      }
    }catch{
      console.log('路由传参非json格式')
    }
    this.headerChange()
    // 待处理人员
    this.initDefaultParam()
    this.queryUndoTaskList()
    localStorage.removeItem('SuperviseDraft');
  },
  computed: {
    // 动态获取scrollX,防止数组固定列的大小变化
    scrollX () {
      return this.columns.reduce((preVal, curVal) => {
        return preVal + curVal.width
      }, 0)
    }
  },
  methods: {
    myEvent (e) {
      if (e) {
        this.scroll.y = this.scroll.y + e
      } else {
        this.scroll.y = 360
      }
    },
    /**
     * 初始化设置默认值
     */
    initDefaultParam () {
      this.queryParam.userid = this.currentUser.userId
      this.queryParam.bizenum = this.Tp_biztype['supervise'].value
      this.queryParam.matid = '100000_360100-000201005000-QT-002-02'
      // this.queryParam.category = 'assignment'
      // this.f_status = this.St_apply[6000600].value 状态
      this.f_status = undefined // 状态
    },

    onSearch (val) {
      this.queryParam.pageNumber = 1
      this.queryParam.f_acceptcode = ''
      if (val) {
        this.queryParam.f_acceptcode = val.toString().trim()
      }
      this.queryList()
    },
    /**
     * 重置查询条件并查询数据
     */
    reQuery () {
      this.queryParam = {
        f_acceptcode: '', // 案号
        f_applyname: '', // 申请人
        f_regusername: '', // 录入人
        f_targetname: '', // 被申请人
        f_applystarttime: null, // 开始时间
        f_applyendtime: null, // 结束时间
        f_source: undefined, // 来源
        pageNumber: 1,
        pageSize: 20,
        sort: 'createtime',
        order: 'desc',
        f_status: undefined // 状态
      }
      this.initDefaultParam()
      this.queryUndoTaskList()
    },

    getCpQueryParam () {
      // 时间转换
      const cpQueryParam = JSON.parse(JSON.stringify(this.queryParam))
      if (this.queryParam.f_applystarttime?.format) {
        cpQueryParam.f_applystarttime = this.queryParam.f_applystarttime.format('YYYY-MM-DD') + ' 00:00:00'
      }
      if (this.queryParam.f_applyendtime?.format) {
        cpQueryParam.f_applyendtime = this.queryParam.f_applyendtime.format('YYYY-MM-DD') + ' 23:59:59'
      }
      return cpQueryParam
    },

    // 接收时间监听判断开始结束日期是否合理
    subtimeListen () {
      if (
        this.queryParam.f_applystarttime > this.queryParam.f_applyendtime &&
        this.queryParam.f_applystarttime &&
        this.queryParam.f_applyendtime
      ) {
        this.queryParam.f_applystarttime = undefined
      }
    },

    queryList () {
      const queryParam = this.getCpQueryParam()
      if (queryParam.f_acceptcode) {
        queryParam.f_acceptcode = queryParam.f_acceptcode.toString().trim()
      }
      if (queryParam.f_targetname) {
        queryParam.f_targetname = queryParam.f_targetname.toString().trim()
      }
      if (queryParam.f_applyname) {
        queryParam.f_applyname = queryParam.f_applyname.toString().trim()
      }
      if (queryParam.f_status) {
        queryParam.f_status = queryParam.f_status.split(',')
      }
      this.loading = true
      queryByPage(queryParam)
        .then(res => {
          if (res.code !== 0) {
            this.$message.error('获取数据失败')
          } else {
            this.listData = res.data.records
            this.$emit('setTotal', res.data.total)
            this.upagination.total = res.data.total
            this.upagination.current = res.data.current
            this.upagination.pageSize = res.data.size
          }
        })
        .catch(err => {
          this.listData = []
          console.log(err, '获取数据失败')
        })
        .finally(() => {
          this.loading = false
        })
    },
    superviseRecordAdd () {
      this.$router.push({
        path: '/SuperviseRecordAdd/add/100000_360100-000201005000-QT-002-02/3',
        query: {
          url: '/SuperviseAssign'
        }
      })
    },
    // 进入复议监督页面
    handleForm (applyid, pattern) {
      this.$router.push({
        path: `/SuperviseRecordAdd/${applyid}/100000_360100-000201005000-QT-002-02/${pattern}`,
        query: {
          url: '/SuperviseDraft',
          queryParam: this.queryParam
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
@import '~@/components/TableDrag/style.less';
</style>

<style lang="scss" scoped>
.cursor_pointer:hover {
  color: #0072C6;
}
.accept_content {
  &_table {
    &_font_red {
      color: #ca0000;
      font-size: 16px;
      font-family: 'PingFang-SC-Heavy';
      font-weight: 400;
    }

    ::v-deep .ant-table-row-cell-break-word {
      font-size: 16px;
      font-family: 'PingFang-SC-Heavy';
      font-weight: 400;
      color: #2c2c2c;
    }

    ::v-deep .ant-table-thead > tr > th {
      height: 50px;
    }

    ::v-deep .ant-table-row-cell-break-word {
      font-size: 16px;
      font-family: 'PingFang-SC-Heavy';
      font-weight: 600;
      color: #2c2c2c;
    }

    // ::v-deep .ant-pagination-total-text {
    //   font-size: 16px;
    //   font-family: 'PingFang-SC-Heavy';
    //   font-weight: 400;
    //   color: #8e97b9;
    // }

    ::v-deep .ant-table-body,
    .ant-table-header {
      word-break: break-all;
      &::-webkit-scrollbar {
        width: 10px; /*高宽分别对应横竖滚动条的尺寸*/
        // height: 10px;
      }
      &::-webkit-scrollbar-thumb {
        border-radius: 6px;
        // -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
        background: #a2c6e1;
      }
      &::-webkit-scrollbar-track {
        // -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
        border-radius: 5px;
        background: transparent;
      }
    }
  }
}
::v-deep .ant-tabs-nav .ant-tabs-tab {
  font-size: 14px;
}

::v-deep .ant-table-bordered .ant-table-fixed-right table {
	border-left: none;
}

</style>
